CMS-204 | Show clear Studio project/config mismatch error instead of cryptic schema hash mismatch#105
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (4)
✅ Files skipped from review due to trivial changes (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughThe PR adds optional project tracking to the schema list API and propagates project-mismatch detection through validation, studio state, and UI. The server returns Changes
Sequence DiagramsequenceDiagram
participant Client
participant API
participant Validator
participant SchemaState
participant UI
Client->>API: GET /api/v1/schema (with x-mdcms-project)
API->>API: resolve project from header
API-->>Client: 200 { data: { project: "server-project", ... } }
Client->>Validator: validateSchemaRegistryListResponse(response)
Validator-->>Client: { project: "server-project", ... }
Client->>SchemaState: loadStudioSchemaState(listResult, config)
SchemaState->>SchemaState: compare listResult.project vs config.project
alt projects match or project absent
SchemaState->>SchemaState: continue schema loading, hash/capability checks
SchemaState-->>Client: { status: "ready", ... }
Client->>UI: render schema browser
else projects mismatch
SchemaState-->>Client: { status: "project-mismatch", configProject, serverProject, environment }
Client->>UI: render project-mismatch banner / deny writes
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 3
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@apps/server/src/lib/schema-api.ts`:
- Line 834: The code is echoing client-provided scope.project into the response
(making Studio's project-mismatch useless); instead derive the authoritative
project from the server-side authenticated context or a server lookup. Replace
uses of scope.project when setting data.project with the server-determined value
(for example requestContext.user.projectId or the result of a helper like
getProjectForUser(user.id) / resolveProjectForAccount(accountId)), and if
necessary add a lookup function call (e.g., getProjectForUser or
getProjectByAccount) before returning the payload so data.project is set from
that authoritative source rather than scope.project.
In `@packages/shared/src/lib/contracts/schema.ts`:
- Around line 76-81: The validation allows empty project strings; update the
check in the payload validation around the local variable project so that a
blank string is rejected: change the condition to ensure project is either
undefined or a non-empty string (e.g. project !== undefined && (typeof project
!== "string" || project.trim() === "")) and call
invalidInput(`${context}.project`, "must be a non-empty string or undefined.", {
project }) to fail on empty values.
In `@packages/studio/src/lib/runtime-ui/pages/content-document-page.tsx`:
- Around line 2719-2726: The dedicated project-mismatch banner branch (checking
state.schemaState?.status === "project-mismatch" and calling
renderProjectMismatchBanner) causes a duplicate generic read-only message later
because that later conditional only excludes "schema-hash-mismatch"; update that
later conditional to also exclude "project-mismatch" (i.e., treat
state.schemaState?.status === "project-mismatch" the same as schema-hash
mismatch) so when renderProjectMismatchBanner is shown the generic read-only
message is suppressed; locate the JSX that renders the generic read-only message
(the conditional that currently checks for schema-hash mismatch) and add the
additional check for "project-mismatch".
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: 728f1b56-9778-4d66-8e17-058adafc7baf
📒 Files selected for processing (8)
apps/server/src/lib/schema-api.test.tsapps/server/src/lib/schema-api.tspackages/shared/src/lib/contracts/schema.test.tspackages/shared/src/lib/contracts/schema.tspackages/studio/src/lib/runtime-ui/app/admin/schema-page.tsxpackages/studio/src/lib/runtime-ui/pages/content-document-page.tsxpackages/studio/src/lib/schema-state.test.tspackages/studio/src/lib/schema-state.ts
…uplicate mismatch banner
Summary by CodeRabbit